home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / e / ddmoduls.lha / dd_Modules / dd_devices / dd_timenotify.e < prev    next >
Text File  |  1995-05-05  |  2KB  |  83 lines

  1. OPT MODULE
  2.  
  3. MODULE 'exec/io'
  4. MODULE 'exec/ports'
  5. MODULE 'exec/nodes'
  6. MODULE 'devices/timer'
  7.  
  8. ENUM EXC_MSGPORT,EXC_TIMEREQUEST,EXC_TIMERDEVICE,EXC_SIGNAL
  9. EXPORT ENUM EXC_TIMENOTIFY
  10.  
  11. RAISE EXC_MSGPORT IF CreateMsgPort()=NIL,
  12.       EXC_TIMEREQUEST IF CreateIORequest()=NIL,
  13.       EXC_TIMERDEVICE IF OpenDevice()<>NIL,
  14.       EXC_SIGNAL IF AllocSignal()=-1
  15.  
  16. -> private timerbase
  17. DEF timerbase
  18.  
  19. EXPORT OBJECT timenotify PRIVATE
  20.   port:PTR TO mp
  21.   timerequest:PTR TO timerequest
  22. ENDOBJECT
  23.  
  24. EXPORT PROC new() OF timenotify HANDLE
  25.   -> create a port used to talk with the device
  26.   self.port:=CreateMsgPort()
  27.   -> create an i/o request, the message we talk with to the device
  28.   self.timerequest:=CreateIORequest(self.port,SIZEOF timerequest)
  29.   -> and open the device we want to use
  30.   OpenDevice('timer.device',UNIT_VBLANK,self.timerequest,0)
  31.   -> set the device base for extended functions
  32.   timerbase:=self.timerequest.io.device
  33. EXCEPT
  34.   -> some allocation failed
  35.   self.end()
  36.   Raise(EXC_TIMENOTIFY)
  37. ENDPROC
  38.  
  39. EXPORT PROC end() OF timenotify
  40.   -> timerequest opened?
  41.   IF self.timerequest
  42.     -> request not yet completed?
  43.     IF CheckIO(self.timerequest)=0
  44.       -> abort request
  45.       AbortIO(self.timerequest)
  46.       -> and wait for it to finish
  47.       WaitIO(self.timerequest)
  48.     ENDIF
  49.     -> timer.device open?
  50.     IF timerbase
  51.       -> close timer.device
  52.       CloseDevice(self.timerequest)
  53.       timerbase:=NIL
  54.     ENDIF
  55.     -> delete request
  56.     DeleteIORequest(self.timerequest)
  57.     self.timerequest:=NIL
  58.   ENDIF
  59.   -> message port open?
  60.   IF self.port
  61.     -> delete message port
  62.     DeleteMsgPort(self.port)
  63.     self.port:=NIL
  64.   ENDIF
  65. ENDPROC
  66.  
  67. EXPORT PROC request(secs,micro) OF timenotify
  68.   -> current request not finished?
  69.   IF CheckIO(self.timerequest)=0
  70.     -> abort request
  71.     AbortIO(self.timerequest)
  72.     -> and wait for it to finish
  73.     WaitIO(self.timerequest)
  74.   ENDIF
  75.   self.timerequest.io.command:=TR_ADDREQUEST
  76.   self.timerequest.time.secs:=secs
  77.   self.timerequest.time.micro:=micro
  78.   -> send request
  79.   SendIO(self.timerequest)
  80. ENDPROC self.signalmask()
  81.  
  82. EXPORT PROC signalmask() OF timenotify IS Shl(1,self.port.sigbit)
  83.